package hot;

import java.util.Arrays;

/**
 * @author way
 * @create 2025-03-02 20:49
 */
public class _4_findMedianSortedArrays {
    public double findMedianSortedArrays(int[] nums1, int[] nums2) {
        int[] nums3 = new int[nums1.length + nums2.length];
        System.arraycopy(nums1, 0, nums3, 0, nums1.length);
        System.arraycopy(nums2, 0, nums3, nums1.length, nums2.length);
        Arrays.sort(nums3);
        int flag = nums3.length % 2;
        if (flag == 0) {
            int right = (nums1.length + nums2.length) / 2;
            return (nums3[right - 1] + nums3[right]) / 2.0;
        } else {
            return nums3[nums3.length / 2];
        }
    }
}
